<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
class Attr extends Controller
{

    /**
     *  分页
     */

    public function show()
    {

        return view('show');
    }


    /**
     * 添加
     */

    public function add()
    {

        if(!Request::instance()->post())
        {
            $data['type'] = model('GoodsAttr')->getAll();
            return view('add',['data'=>$data]);
        }

        $data = Request::instance()->post();

        $timeNow = date('Y-m-d H:i:s',time());
        $userId = 1;
        $data['status'] = 1;
        $data['create_user'] = $userId;
        $data['create_time'] = $timeNow;
        $data['update_user'] = $userId;
        $data['update_time'] = $timeNow;

        //调用模型层添加
        $res = model('GoodsAttr')->addOne($data);
      
        if(!$res)
        {
            $this->redirect('Attr/add');
        }
        $this->redirect('Attr/show');
     }

     public function getAttrByTypeId()
     {
        $type_id = Request::instance()->post('type_id','');
        $data = model('GoodsAttr')->getAttrByTypeId($type_id);

        $arr['code'] = 1;
        $arr['msg'] = 'ok';
        $arr['data'] = $data;
         return $arr;
     }
}
